package Scene;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.mt4j.MTApplication;
import org.mt4j.components.TransformSpace;
import org.mt4j.components.visibleComponents.font.FontManager;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import org.mt4j.components.visibleComponents.widgets.MTTextArea;
import org.mt4j.components.visibleComponents.widgets.buttons.MTImageButton;
import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
import org.mt4j.input.inputProcessors.globalProcessors.CursorTracer;
import org.mt4j.sceneManagement.AbstractScene;
import org.mt4j.sceneManagement.Iscene;
import org.mt4j.sceneManagement.transition.BlendTransition;
import org.mt4j.sceneManagement.transition.FadeTransition;
import org.mt4j.util.MT4jSettings;
import org.mt4j.util.MTColor;
import org.mt4j.util.math.Vector3D;
import org.mt4j.util.opengl.GLFBO;

import processing.core.PImage;

public class FingerBreakMainScene extends AbstractScene {
	private MTApplication mtApp;
	private Iscene scene2;
	
//	private String imagePath = System.getProperty("user.dir") + File.separator + "examples"+  File.separator +"basic"+  File.separator + "scenes" + File.separator + "data" + File.separator;	
	public FingerBreakMainScene(MTApplication mtApplication, String name) {
		super(mtApplication, name);
		this.mtApp = mtApplication;
		
		//Set the background color
		this.setClearColor(new MTColor(146, 150, 188, 255));
		
		this.registerGlobalInputProcessor(new CursorTracer(mtApp, this));
		
		PImage background = mtApplication.loadImage("images/Background.png");
		MTRectangle backgroundRec = new MTRectangle(background, mtApp);
		backgroundRec.setPositionGlobal(new Vector3D(mtApp.width/2f, mtApp.height/2f));
		backgroundRec.removeAllGestureEventListeners();
		this.getCanvas().addChild(backgroundRec);

		
		//Button to get to the next scene
		PImage arrow = mtApplication.loadImage("images/newgamebutton.png");
		MTImageButton nextSceneButton = new MTImageButton(arrow, mtApplication);
		nextSceneButton.setNoStroke(true);
		if (MT4jSettings.getInstance().isOpenGlMode())
			nextSceneButton.setUseDirectGL(true);
		nextSceneButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				switch (ae.getID()) {
				case TapEvent.BUTTON_CLICKED:
					//Save the current scene on the scene stack before changing
					mtApp.changeScene(new FingerBreakScene(mtApp, "Finger Break Scene"));
					break;
				default:
					break;
				}
			}
		});
		getCanvas().addChild(nextSceneButton);
		nextSceneButton.setPositionGlobal(new Vector3D(mtApp.width/2, mtApp.height/2 + 100));
		
		//Set a scene transition - Flip transition only available using opengl supporting the FBO extenstion
		if (MT4jSettings.getInstance().isOpenGlMode() && GLFBO.isSupported(mtApp))
			this.setTransition(new BlendTransition(mtApp, 700));
		else{
			this.setTransition(new FadeTransition(mtApplication, 1700));
		}
	}
	

	@Override
	public void init() {
		System.out.println("Entered scene: " +  this.getName());
	}

	@Override
	public void shutDown() {
		System.out.println("Left scene: " +  this.getName());
	}
}